package com.ijecorp.media.riff;

import java.util.ArrayList;
import java.util.List;

public class WAVEChunk extends RIFFChunk{
	public static final int WAVE_ID = 0x57415645 ;
	private List<RIFFChunk> subChunks = new ArrayList<RIFFChunk>();
	protected int format;
	
	protected WaveDataChunk dataChunk;
		
	public WAVEChunk(int riffID, int size, int format) {
		super(riffID, size);
		this.format = format;
	}	
	
	public final void addSubChunk(RIFFChunk chunk){
		this.subChunks.add(chunk);
	}
	

	
	public final byte[] getSampleData(){
		throw new RuntimeException("Not yet!");
	}
}


class WaveFmtChunk extends RIFFChunk{
	public static final int FMT_ID = 0x666d7420; //: fmt
	short code;
	short channels;
	int sampleRate;
	int byteRate;
	short blockAlign;
	short bitsPerSample;
	byte extraData[];
	public WaveFmtChunk(int ID, int size) {
		super(ID, size);
	}
}

class WaveDataChunk extends RIFFChunk{
	public static final int DATA_ID = 0x64617461 ; //: data
	protected final byte[] data;
	public WaveDataChunk(byte[] data) {
		super(DATA_ID, data.length);
		this.data = data;
	}	
}

class WaveFactChunk extends RIFFChunk{
	public static final int FACT_ID = 0x66616374 ; //: fact
	protected final byte[] data;	
	public WaveFactChunk(byte[] data) {
		super(FACT_ID, data.length);
		this.data = data;
	} 
}

class WaveListChunk extends RIFFChunk{
	public static final int LIST_ID = 0x736C6E74 ; //: wavl
	public WaveListChunk(int ID, int size) {
		super(LIST_ID, size);
	}
	
}

class WaveSilentChunk extends RIFFChunk{
	public static final int SILENT_ID = 0x736C6E74 ; //: slnt	
	final int numSilentSamples;
	public WaveSilentChunk(int size, int numSilentSamples){
		super(SILENT_ID, size);
		this.numSilentSamples = numSilentSamples;
	}
}

class WaveCueChunk extends RIFFChunk{
	public static final int CUE_ID = 0x63756520 ; //: 'cue '
	final int cuePoints;
	private List<CuePoint> points = new ArrayList<CuePoint>();
	public WaveCueChunk(int size, int points) {
		super(CUE_ID, size);
		this.cuePoints = points;
	}	
	
	public final void addCuePoint(CuePoint p){
		this.points.add(p);
	}
}

class CuePoint{
	int ID;
	int position;
	int chunkID;
	int chunkStart;
	int blockStart;
	int sampleOffset;
	public CuePoint(){		}
}

class PlayListChunk extends RIFFChunk{
	public static final int PLST_ID =0x736C6E74 ; //: 'plst'
	final int numOfSegments;
	
	private List<Segment> segments = new ArrayList<Segment>();
	public PlayListChunk(int size, int segments) {
		super(PLST_ID, size);
		this.numOfSegments = segments;
	}
	public final void addSegment(Segment s){
		this.segments.add(s);
	}
	
}

class Segment{
	int cuePointID;
	int lenInSample;
	int numRepeats;
}



class AssociatedDataListChunk extends RIFFChunk{
	public static final int LIST_ID =0x6C696E74 ; //: 'list'
	public static final int ADTL_ID =0x6164746C ; //: 'adtl'
	
	private List<String> labels = new ArrayList<String>();
	public AssociatedDataListChunk(int size) {
		super(LIST_ID, size);
	}
	
	public final void addLabel(String labelID){
		this.labels.add(labelID);
	}
}

class LabelChunk extends RIFFChunk{
	public static final int LABL_ID =0x6C61626C ; //: 'labl'
	final int cuePointID;
	final String text ;
	public LabelChunk(int size, int cuePointID, String text) {
		super(LABL_ID,size);
		this.cuePointID = cuePointID;
		this.text = text;
	}	
}

class NoteChunk extends RIFFChunk{

	public static final int NOTE_ID =0x6E6F7465 ; //: 'note'
	public NoteChunk(int size, int cuePointID, String text) {
		super(NOTE_ID, size);
	}
	
}

